package com.heima.common.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * Integer到Boolean的序列化器
 * 将数据库中的0/1转换为前端需要的true/false
 */
public class IntegerToBooleanSerializer extends JsonSerializer<Integer> {
    
    @Override
    public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value != null) {
            gen.writeBoolean(value == 1);
        } else {
            gen.writeNull();
        }
    }
}
